package xmlrpc.gui;

import javax.swing.WindowConstants;

import xmlrpc.server.ConServer;

public class ServerMainFrameController {
	private static ServerMainFrameController me;
	//TODO Priority 2 create constant for standard server port
	private static int port = 1337;
	ConServer server = new ConServer();
	ServerMainFrame mf;

	
	public static ServerMainFrameController getInstance(){
		if(me == null)
			me = new ServerMainFrameController();
		return me;
	}

	public void startServer(){
		try {
			server.startServer(port);
			mf = new ServerMainFrame();
			mf.setVisible(true);
			mf.textArea.append("Server started at port " + port + "\n");
			// TODO Priority 1 add windowlistener to mf(?) and terminate server via
			// the windowlistener
			mf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void shutdownServer(){
		server.stopServer();
		System.out.println("Server stopped!");
	}


}
